import axios from 'axios';
import {message,} from 'antd';
import router from 'umi/router';
// import qs from 'qs';

axios.defaults.baseURL = 'https://seventh.chinacloudsites.cn/api/';

const request1 = (url, params) => {
  return axios({
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      Authorization: ''
    },
    method: params.method||'GET',
    url,
    params: {
      ...params.payload||params.data,
      timestamp:new Date().getTime()
    },
    data:{
      ...params.data||params.payload,
      timestamp:new Date().getTime()}
  }).then( response =>  {
    if (response.status === 200) {
      return Promise.resolve(response.data);
    }else if(response.status === 401){
      message.error('你的账号状态过期，请重新登录一下');
    }
    // eslint-disable-next-line consistent-return
  }, error => {
    if(error.response.status == 401){
      message.error('你的账号状态过期，请重新登录一下');
      router.push("/user")
    }else{
      message.error(error.response.data.error.message);
      return Promise.reject(error.response);
    }
  })
};

export default request1;

